package snowforce;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import snowforce.datatype.MapJSON;
import snowforce.storage.MapJSONStore;

@Path("/map")
public class MapService
{

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public MapJSON getMapJSON(@QueryParam("level") String levelStr, @DefaultValue("0") @QueryParam("dummy") String dummy)
	{
		MapJSON ret = new MapJSON();
		// ret = getDefault();
		int level = 0;
		try {
			System.out.println("ab233c");
			level = Integer.parseInt(levelStr);
			System.out.println("abc222");
		}
		catch (Exception e) {
			e.printStackTrace();
			ret.setStatus("PARAM_LEVEL_WRONG");
			return ret;
		}
		// loadMapFile(level + "");
		// String mapData = mjs.get("" + level);
		String mapData = MapJSONStore.getStore().get("" + level);
		ret = new MapJSON("OK", mapData);
		return ret;
	}

	private MapJSON getDefault()
	{
		MapJSON a = new MapJSON();
		a.setMap("map level:---+");
		a.setStatus("OK");
		return a;
	}

}